package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProPlan;
import com.ruoyi.system.service.IProPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目计划Controller
 *
 * @author ruoyi
 * @date 2024-10-07
 */
@RestController
@RequestMapping("/system/plan")
public class ProPlanController extends BaseController
{
    @Autowired
    private IProPlanService proPlanService;

    /**
     * 查询项目计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProPlan proPlan)
    {
        startPage();
        List<ProPlan> list = proPlanService.selectProPlanList(proPlan);
        return getDataTable(list);
    }

    /**
     * 导出项目计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:export')")
    @Log(title = "项目计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProPlan proPlan)
    {
        List<ProPlan> list = proPlanService.selectProPlanList(proPlan);
        ExcelUtil<ProPlan> util = new ExcelUtil<ProPlan>(ProPlan.class);
        util.exportExcel(response, list, "项目计划数据");
    }

    /**
     * 获取项目计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:plan:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId)
    {
        return success(proPlanService.selectProPlanByPlanId(projectId));
    }

    /**
     * 新增项目计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:add')")
    @Log(title = "项目计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProPlan proPlan)
    {
        return toAjax(proPlanService.insertProPlan(proPlan));
    }

    /**
     * 修改项目计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:edit')")
    @Log(title = "项目计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProPlan proPlan)
    {
        return toAjax(proPlanService.updateProPlan(proPlan));
    }

    /**
     * 删除项目计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:remove')")
    @Log(title = "项目计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds)
    {
        return toAjax(proPlanService.deleteProPlanByPlanIds(planIds));
    }
}
